<?php
Globals::requireController('Admin');
Globals::requireTable('User');

class UserInfoController extends AdminController
{
	protected $userTable;
	protected $userid;
	
	public function __construct($config = null)
	{
		parent::__construct($config, true);
		
		$this->userTable= new UserTable($config);
		$this->userid	= $this->userInfo['id'];
	}
	
	public function indexAction()
	{
		$this->redirectToController();
	}
	
	public function modifyAction()
	{
		$this->view->row = $this->userTable->getRow($this->userid);
	}
	
	public function modifyPostAction()
	{
		$params	= $this->getParams('realname');
		$result	= $this->userTable->modify($params, $this->userid);
		
		if ($result)
			$_SESSION['userInfo'] = array_merge($_SESSION['userInfo'], $params);
		
		$this->log('修改资料'.($result ? '成功' : '失败'));
		$this->redirectToAction();
	}
	
	public function modifyPasswordAction()
	{
	}
	
	public function modifyPasswordPostAction()
	{
		$result = $this->userTable->modify($this->getParams('password'), $this->userid);
		$this->log('修改密码'.($result ? '成功' : '失败'));
		$this->redirectToAction();
	}
}
